package org.example;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
        // 基础数据类型
        int age = 10;
        double height = 1.75;
        char gender = 'M';
        boolean isMarried = true;

        System.out.println("My age is " + age);
        System.out.println("My height is " + height);
        System.out.println("My gender is " + gender);
        System.out.println("I am " + (isMarried ? "married" : "not married"));

        //引用数据类型
        String name = "Tom";
        int[] numbers = {85, 90, 95};


        System.out.println("My name is " + name);
        System.out.println("My scores are " + Arrays.toString(numbers));

        for (int numner : numbers) {
            System.out.println(numner);
        }


        for (int i = 1; i <= 5; i++) {
            System.out.println("i = " + i);
        }

        class Person {
            private String name;
            private int age;

            public Person(String name, int age) {
                this.name = name;
                this.age = age;
            }

            public void sayHello() {
                System.out.println("Hello, my name is " + name + ", and I'm " + age + " years old.");
            }
        }


        Person person = new Person("Jane", 25);
        person.sayHello();
        System.out.println("My person is " + person);
        System.out.println("My person is " + person.toString());


        Animal animal = new Dog();
        boolean isDog = animal instanceof Dog;
        System.out.println("animal 是 Dog 的实例吗？ " + isDog);


        long startTime1 = System.currentTimeMillis();

        System.out.println("开始时间1：" + startTime1);

        String strs = "123456";
        for (int i = 0; i < strs.length(); i++) {
            System.out.println(strs.charAt(i));
        }

        // 封装：将数据和操作数据的方法封装在一起，通过访问修饰符（private、protected、public）来控制对数据的访问
        class Person2 {
            private String name;
            private int age;

            public String getName() {
                return name;
            }

            public void setName(String name) {
                this.name = name;
            }

            public int getAge() {
                return age;
            }

            public void setAge(int age) {
                this.age = age;
            }
        }


        //继承：一个类可以继承另一个类的属性和方法，使用 extends 关键字。
        class Student extends Person2 {
            private String studentId;

            public String getStudentId() {
                return studentId;
            }

            public void setStudentId(String studentId) {
                this.studentId = studentId;
            }
        }


        //多态：同一个方法可以根据对象的不同类型表现出不同的行为。
        class Animal {
            public void makeSound() {
                System.out.println("Animal makes sound");
            }
        }

        class Dog extends Animal {
            @Override
            public void makeSound() {
                System.out.println("Woof!");
            }
        }

        class Cat extends Animal {
            @Override
            public void makeSound() {
                System.out.println("Meow!");
            }
        }


        class Circle {
            private double radius;

            public Circle(double radius) {
                this.radius = radius;
            }

            public double getArea() {
                return Math.PI * radius * radius;
            }
        }

        Circle circle = new Circle(5.0); // 实例化
        double area = circle.getArea();
        System.out.println("Area of the circle: " + area);

        class MathUtils {
            //在 Java 中，`static` 关键字用于定义类的静态成员。当方法被声明为 `static` 时，它属于类本身，
            //而不是类的实例。这意味着你可以在不创建类的实例的情况下调用该方法。下面详细解释 `static`
            // 关键字的作用以及如果不使用 `static` 会有什么区别。
            public static int add(int a, int b) {
                return a + b;
            }
        }

        int result = MathUtils.add(3, 5); // 不需要实例化就可以直接调用类本身上的方法add
        System.out.println("Sum: " + result);

//      List  Map

        List<String> list = new ArrayList<>();
        list.add("test");
        System.out.println(list);
        list.add("Alice");
        list.add("Bob");
        for (String l : list) {
            System.out.println(l);
        }

        Map<String, Integer> map = new HashMap<String, Integer>();
        map.put("Alice", 25);
        map.put("Bob", 30);

        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            System.out.println(entry.getKey() + ": " + entry.getValue());
        }

    }
}